Option Strict On
Option Explicit On

Imports System.ComponentModel
Imports System.ComponentModel.Design

Public Class PivotTableWrapperActionList
    Inherits DesignerActionList

    Private m_pivotTableWrapper As PivotTableWrapper

    Public Sub GetXMLDataInteractively()
        Dim form As New PivotTableDesignerForm
        Dim returnedData As String = ""

        If m_pivotTableWrapper.XmlData <> "" Then
            form.XmlData = m_pivotTableWrapper.XmlData
        End If

        If form.ShowDialog() = Windows.Forms.DialogResult.OK Then
            If form.IsDirty Then
                ' TODO: Collect other properties
                returnedData = form.XmlData
            End If
        End If

        form.Close()
        form.Dispose()

        If returnedData <> "" Then
            ' This method of setting the property of the 
            ' control ensures that Undo/redo in the design 
            ' host application works as expected.
            Dim pd As PropertyDescriptor _
                = TypeDescriptor.GetProperties(m_pivotTableWrapper) _
                .Item("XmlData")

            pd.SetValue(m_pivotTableWrapper, returnedData)
        End If
    End Sub

    Public Overrides Function GetSortedActionItems() As DesignerActionItemCollection
        Dim items As New DesignerActionItemCollection()

        items.Add( _
                New DesignerActionHeaderItem("PivotTable Actions") _
        )

        items.Add( _
                New DesignerActionMethodItem( _
                            Me, _
                            "GetXMLDataInteractively", _
                            "Set properties visually", _
                            "PivotTable Actions", _
                            "Visually set the Pivottable properties.", _
                            True _
                ) _
        )

        Return items
    End Function

    Sub New(ByVal component As IComponent)
        MyBase.New(component)

        m_pivotTableWrapper = DirectCast( _
                                    component, _
                                    PivotTableWrapper _
                            )
    End Sub
End Class
